/// home.dart
import 'package:flutter/material.dart';

import './pages/first_page.dart';
import './pages/second_page.dart';

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final items = [
    BottomNavigationBarItem(icon: Icon(Icons.home), label: '指标总计'),
    BottomNavigationBarItem(icon: Icon(Icons.person), label: '供电所列表'),
  ];
  final bodyList = [FirstPage(), SecondPage()];
  final pageController = PageController();
  int currentIndex = 0;
  void onTap(int index) {
    pageController.jumpToPage(index);
  }

  void onPageChanged(int index) {
    setState(() {
      currentIndex = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        bottomNavigationBar: BottomNavigationBar(
            type: BottomNavigationBarType.fixed,
            items: items,
            currentIndex: currentIndex,
            onTap: onTap),
        body: PageView(
          controller: pageController,
          onPageChanged: onPageChanged,
          children: bodyList,
        ));
  }
}
